﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Guoc.DAL.Domain;
namespace Guoc.Web.Tool
{
    public class Admin
    {
        /// <summary>
        /// 当前登录用户Session值
        /// </summary>
        const string CURRENTUSER = "currentUser";

        public static Employee Current
        {
            get {
                if (HttpContext.Current.Session[CURRENTUSER] == null)
                {   
                    return null;
                }
                else{
                    Employee emp = HttpContext.Current.Session[CURRENTUSER] as Employee;
                    return emp;
                }
            }
        }

        /// <summary>
        /// 保存当前管理员信息
        /// </summary>
        /// <param name="user"></param>
        public static void SetAdmin(Employee user)
        {
            user.LastLoginDate = DateTime.Now;
            user.LastLoginIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();

            HttpContext.Current.Session[CURRENTUSER] = user;           
        }
        /// <summary>
        /// 清除当前管理员信息
        /// </summary>
        public static void ClearAdmin()
        {
            HttpContext.Current.Session[CURRENTUSER] = null;
            HttpContext.Current.Session.Clear();   
        }
        
    }
}